Conversation
|
/cc @digitalinfinity @jasongin @gabrielschulhof Ignore the changes to |
test/index.js
Outdated
| args.splice(0, 0, '--napi-modules'); | ||
| } | ||
| const child = require('child_process').spawnSync(process.argv[0], args, { | ||
| const child = require('./napi_child').spawnSync(process.argv[0], args, { |
There was a problem hiding this comment.
Did you intend to delete the splicing lines above?
src/node_internals.h
Outdated
|
|
||
| #ifndef SRC_NODE_INTERNALS_H_ | ||
| #define SRC_NODE_INTERNALS_H_ | ||
|
|
There was a problem hiding this comment.
Can you put a comment in here explaining that this is not the real, complete "node_internals", but just a shim for building node_api.cc outside of node?
napi-inl.h
Outdated
| #endif // NAPI_CPP_EXCEPTIONS | ||
|
|
||
| #define NAPI_FATAL_IF_FAILED(status, location, message) \ | ||
| if ((status) != napi_ok) Error::Fatal((location), (message)); |
There was a problem hiding this comment.
Suggestion: wrap this in a do { ... } while so that if (...) NAPI_FATAL_IF_FAILED(...); else ... does the right thing.
src/node_api.cc
Outdated
| v8::ObjectTemplate::New(isolate); | ||
| wrapperTemplate->SetInternalFieldCount(1); | ||
| v8::Local<v8::Object> wrapper = | ||
| wrapperTemplate->NewInstance(context).ToLocalChecked(); |
There was a problem hiding this comment.
Style: indent line continuations by four spaces, not two.
src/node_api.cc
Outdated
|
|
||
| obj->SetInternalField(0, v8::External::New(isolate, native_object)); | ||
| // Create a wrapper object with an internal field to hold the wrapped pointer. | ||
| v8::Local<v8::ObjectTemplate> wrapperTemplate = |
There was a problem hiding this comment.
Style: wrapper_template (snake_case, not camelCase, for locals.)
Substance: creating an ObjectTemplate every time leaks memory. V8 caches them internally and it doesn't put an upper bound or a lifetime on elements in the cache. Create a single ObjectTemplate and reuse that.
There was a problem hiding this comment.
Hmm ... we do this upstream as well.
src/node_api.cc
Outdated
| // Insert the wrapper into the object's prototype chain. | ||
| v8::Local<v8::Value> proto = obj->GetPrototype(); | ||
| wrapper->SetPrototype(proto); | ||
| obj->SetPrototype(wrapper); |
There was a problem hiding this comment.
Can you use the Maybe overloads here?
src/node_internals.h
Outdated
| @@ -0,0 +1,90 @@ | |||
| // Copyright Joyent, Inc. and other Node contributors. | |||
There was a problem hiding this comment.
There was a problem hiding this comment.
Thanks @bnoordhuis, I was looking for some guidance here. I'll change the copyright headers.
test/error.js
Outdated
| process.execPath, [ __filename, 'fatal', bindingPath ]); | ||
| assert.ifError(p.error); | ||
| assert.ok(p.stderr.toString().includes( | ||
| 'FATAL ERROR: Error::ThrowFatalError This is a fatal error')); |
There was a problem hiding this comment.
Style: 4 space indent for line continuations.
V8 caches and does not subsequently release `ObjectTemplate` instances. Thus, we need to store the `ObjectTemplate` from which we derive object instances we use for `napi_wrap()` and function/accessor context in a persistent in the `napi_env`. nodejs/node-addon-api#70 (comment)
V8 caches and does not subsequently release `ObjectTemplate` instances. Thus, we need to store the `ObjectTemplate` from which we derive object instances we use for `napi_wrap()` and function/accessor context in a persistent in the `napi_env`. nodejs/node-addon-api#70 (comment) PR-URL: #13999 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.co> Reviewed-By: Hitesh Kanwathirtha <digitalinfinity@gmail.com>
V8 caches and does not subsequently release `ObjectTemplate` instances. Thus, we need to store the `ObjectTemplate` from which we derive object instances we use for `napi_wrap()` and function/accessor context in a persistent in the `napi_env`. nodejs/node-addon-api#70 (comment) PR-URL: #13999 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.co> Reviewed-By: Hitesh Kanwathirtha <digitalinfinity@gmail.com>
|
@kfarnung Is this ready to merge? It looks like you've addressed @bnoordhuis's feedback. |
|
I was waiting on the upstream change (nodejs/node#13971) to land before trying to get this merged. |
|
I guess this now needs to be rebased to remove the changes to the node files. |
|
Yup, I'll take care of that momentarily. |
* Added static method `Error::Fatal` to invoke `napi_fatal_error` * Added `node_internals.cc/h` to shim missing internal functions * Added a test for `Error::Fatal` * Replaced usage of assert with calls to `Error::Fatal`
|
Rebased one last time and new CI run: https://travis-ci.org/kfarnung/node-addon-api/builds/253725282 |
|
Looks like Ben's comments have been addressed so landing. |
* Added static method `Error::Fatal` to invoke `napi_fatal_error` * Added `node_internals.cc/h` to shim missing internal functions * Added a test for `Error::Fatal` * Replaced usage of assert with calls to `Error::Fatal` PR-URL: #70 Reviewed-By: Jason Ginchereau <jasongin@microsoft.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
|
landed as 28fad43 |
V8 caches and does not subsequently release `ObjectTemplate` instances. Thus, we need to store the `ObjectTemplate` from which we derive object instances we use for `napi_wrap()` and function/accessor context in a persistent in the `napi_env`. nodejs/node-addon-api#70 (comment) PR-URL: #13999 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.co> Reviewed-By: Hitesh Kanwathirtha <digitalinfinity@gmail.com>
V8 caches and does not subsequently release `ObjectTemplate` instances. Thus, we need to store the `ObjectTemplate` from which we derive object instances we use for `napi_wrap()` and function/accessor context in a persistent in the `napi_env`. nodejs/node-addon-api#70 (comment) PR-URL: #13999 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.co> Reviewed-By: Hitesh Kanwathirtha <digitalinfinity@gmail.com>
V8 caches and does not subsequently release `ObjectTemplate` instances. Thus, we need to store the `ObjectTemplate` from which we derive object instances we use for `napi_wrap()` and function/accessor context in a persistent in the `napi_env`. nodejs/node-addon-api#70 (comment) PR-URL: nodejs#13999 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.co> Reviewed-By: Hitesh Kanwathirtha <digitalinfinity@gmail.com>
V8 caches and does not subsequently release `ObjectTemplate` instances. Thus, we need to store the `ObjectTemplate` from which we derive object instances we use for `napi_wrap()` and function/accessor context in a persistent in the `napi_env`. nodejs/node-addon-api#70 (comment) Backport-PR-URL: #19447 PR-URL: #13999 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.co> Reviewed-By: Hitesh Kanwathirtha <digitalinfinity@gmail.com>
* Added static method `Error::Fatal` to invoke `napi_fatal_error` * Added `node_internals.cc/h` to shim missing internal functions * Added a test for `Error::Fatal` * Replaced usage of assert with calls to `Error::Fatal` PR-URL: nodejs/node-addon-api#70 Reviewed-By: Jason Ginchereau <jasongin@microsoft.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
* Added static method `Error::Fatal` to invoke `napi_fatal_error` * Added `node_internals.cc/h` to shim missing internal functions * Added a test for `Error::Fatal` * Replaced usage of assert with calls to `Error::Fatal` PR-URL: nodejs/node-addon-api#70 Reviewed-By: Jason Ginchereau <jasongin@microsoft.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
* Added static method `Error::Fatal` to invoke `napi_fatal_error` * Added `node_internals.cc/h` to shim missing internal functions * Added a test for `Error::Fatal` * Replaced usage of assert with calls to `Error::Fatal` PR-URL: nodejs/node-addon-api#70 Reviewed-By: Jason Ginchereau <jasongin@microsoft.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
* Added static method `Error::Fatal` to invoke `napi_fatal_error` * Added `node_internals.cc/h` to shim missing internal functions * Added a test for `Error::Fatal` * Replaced usage of assert with calls to `Error::Fatal` PR-URL: nodejs/node-addon-api#70 Reviewed-By: Jason Ginchereau <jasongin@microsoft.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Error::Fatalto invokenapi_fatal_errornode_internals.cc/hto shim missing internal functionsError::Fatal